<html>
<head></head>
<body>
    <h1>test</h1><br>
    <a href="https://google.com">go</a>
    <script>
        window.onbeforeunload = function(e){
            console.log(document.activeElement)
            alert(document.activeElement.href );
            e.returnValue = '/o'
        }
        setTimeout(() => {
            window.location.href = "https://baidu.com"
        }, 10000);
    </script>
</body>
</html>